package com.vil.service.impl;



import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vil.common.ServerResponse;
import com.vil.entity.Active;
import com.vil.mapper.ActiveMapper;
import com.vil.service.ActiveService;

@Service
public class ActiveServiceImpl implements ActiveService {
	 @Autowired
	 private ActiveMapper mapper;
	 
	 @Override
	public ServerResponse deleteByPrimaryKey(Long id) {
		 if (id<1){
	            return ServerResponse.buildErrorMsg("参数不合法");
	        }
		int i =mapper.deleteByPrimaryKey(id);
		if(i>0){
			return ServerResponse.buildSuccessMsg("删除成功");
		}
		return ServerResponse.buildErrorMsg("删除失败");
	}

	@Override
	public ServerResponse insertSelective(Active record) {
		if (record==null){
            return ServerResponse.buildErrorMsg("参数不能为空");
        }
		int i =mapper.insertSelective(record);
		if(i>0){
			return ServerResponse.buildSuccessMsg("新增成功");
		}
		return ServerResponse.buildErrorMsg("新增失败");
	}


	@Override
	public ServerResponse updateByPrimaryKeySelective(Active record) {
		if (record==null){
            return ServerResponse.buildErrorMsg("参数不能为空");
        }
		int i=mapper.updateByPrimaryKeySelective(record);
		if (i>0){
            return ServerResponse.buildSuccessMsg("修改成功");
        }
        return ServerResponse.buildErrorMsg("修改失败");
	}

	@Override
	public ServerResponse getListByManyConditions(Integer pageIndex, Integer pageSize, Active record) {
		PageHelper.startPage(pageIndex,pageSize);
		List<Active> list=mapper.getListByManyConditions(record);
		PageInfo pageInfo = new PageInfo(list);
		if (pageInfo!=null){
            return ServerResponse.buildSuccessData(pageInfo);
        }
        return ServerResponse.buildErrorMsg("列表不存在");
    }


//	@Override
//	public ServerResponse getListByManyConditions(Integer pageIndex, Integer pageSize, String village) {
//		PageHelper.startPage(pageIndex,pageSize);
//		List<Active> list=mapper.getListByManyConditions(village);
//		PageInfo activePageInfo = new PageInfo(list);
//		return ServerResponse.buildSuccessData(activePageInfo);
//	}

	@Override
	public ServerResponse getById(Long id) {
		if (id<1||id==null){
            ServerResponse.buildErrorMsg("参数不合法");
        }
		Active active =mapper.selectByPrimaryKey(id);
		if (active==null){
            return ServerResponse.buildErrorMsg("不存在该活动信息");
        }
        return ServerResponse.buildSuccessData(active);
	}

	@Override
	public ServerResponse deleteMany(Long[] ids) {
		if (ids==null){
            return ServerResponse.buildErrorMsg("数组不能为空");
        }
		int i = mapper.deleteMany(ids);
        if (i>0){
            return ServerResponse.buildSuccessMsg("批量删除成功");
        }
        return ServerResponse.buildErrorMsg("批量删除失败");
		
	}

//	@Override
//	public ServerResponse isExist(String village) {
//		int exist =mapper.isExist(village);
//		if (exist>0){
//	           return ServerResponse.buildErrorMsg("该活动已存在，请重新输入");
//	        }
//	        return ServerResponse.buildSuccessMsg("该活动可以参加");
//	    }
	
	}

	


